package w83a.w83aOperacionesPaso.w83aDocumentacion;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import w83a.w83aBeans.W83aDocumentoBean;
import w83a.w83aUtilidades.W83aUtilidadesComunes;
import w83a.w83aUtilidadesComunes.W83aClsTrazas;
import es.ejie.frmk.presentacion.operacion.paso.Q70ActionPasoOP;
import es.ejie.frmk.presentacion.sesiondatos.Q70ContextoEJIE;

// TODO: Auto-generated Javadoc
/**
 * The Class W83bTablaAgrupacionesOP.java.
 *
 * @author Deusto Sistemas
 */
public class W83aTablaDocumentaciondocumentosOutOPAction extends Q70ActionPasoOP{

	
	protected void processOP(Q70ContextoEJIE contexto, ActionErrors errores, ActionMapping mapping,
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		//Guardamos la accion en el contexto
	}

	protected ActionForward processForward(Q70ContextoEJIE contexto, ActionErrors errors, ActionMapping mapping, 
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		HashMap lista=(HashMap)contexto.get("w83aListaDocumentacion");

		
		List documentos=(ArrayList)lista.get("documentos");
		W83aDocumentoBean bean = (W83aDocumentoBean)contexto.get("w83aDocumentoBean");
		int num_paginas = documentos.size()/Integer.parseInt(bean.getTotal());
		
		W83aClsTrazas.trazaDebug(null, "  num_paginas:  " +num_paginas);
		if(documentos.size()%Integer.parseInt(bean.getTotal())>0){
			num_paginas++;
		}
		bean.setRows(String.valueOf(num_paginas));
		W83aClsTrazas.trazaDebug(null, "  String.valueOf(num_paginas):  " +String.valueOf(num_paginas));
		
		List listaVariables = new ArrayList();
		listaVariables.add("clave");
		listaVariables.add("nombre");
		listaVariables.add("descTipo");
		listaVariables.add("fechaRegistro");
		listaVariables.add("numeroRegistro");
		
		String varClave = "clave";
		
		String jJson = W83aUtilidadesComunes.procesarTabla(documentos,listaVariables,varClave,W83aDocumentoBean.class, bean);
		W83aClsTrazas.trazaDebug(null, "  vuelve de procesar tabla  " );
		response.setContentType("text/javascript;charset=iso-8859-1");
		response.setHeader("Pragma", "cache");
		response.setHeader("Expires", "0");
		response.setHeader("Cache-Control", "private");
		response.setStatus(HttpServletResponse.SC_OK);
		PrintWriter out = response.getWriter();

		out.print(jJson);
		out.flush();
		
		return null;
	}
	


}
